package cn.yeamin.ms.config.intercepter;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import cn.yeamin.ms.vo.User;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @classDesc: 功能描述:(配置只允许登陆一次的拦截器)
 * @author: 滕康全
 * @createTime: 2017/7/3 19:06:32
 * @version: v1.0
 * @copyright:善林(上海)金融信息服务有限公司
 */
@Component
public class LoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o) throws Exception {
    	User user = (User)httpServletRequest.getSession().getAttribute("user");
        if (null != user && user.getStatus() == 1){
        	System.out.println("--------------------------账号被人禁用了--------------------------");
            httpServletResponse.sendRedirect(httpServletRequest.getContextPath()+"/admin/login");
            return false;
        }
        //httpServletRequest.getRequestDispatcher("/admin/index").forward(httpServletRequest,httpServletResponse);
        return true;
    }

    @Override
    public void postHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, ModelAndView modelAndView) throws Exception {

    }

    @Override
    public void afterCompletion(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) throws Exception {

    }
}
